home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news
- From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
- Newsgroups: comp.lang.c++
- Subject: Re: New operator
- Date: Wed, 14 Feb 1996 09:14:07 +0100
- Organization: Fachbereich Informatik, TH Darmstadt
- Message-ID: <312199CF.41C67EA6@intellektik.informatik.th-darmstadt.de>
- References: <1996Feb14.022723.6407@cronkite.res.utc.com>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3 sun4m)
-
- Marco DeFreitas wrote:
- >
- > If I use the explicit placement form of new to create an object from
- > some specified memory, can I delete it?
- >
- > char buf[100];
- > Object *obj;
- >
- > obj = new (buf) Object;
- > delete obj;
- >
- > What actually happens? I tried it on an SGI version of C++ and it does
- > not complain - but is this legal? Is it really doing a delete of my buf?
- > Or is the delete being ignored. Thanks in advance for any input.
- >
-
- 'delete' is the wrong choice. It would free memory that wasn't
- allocated via 'new'. Use a direct call of the dtor instead:
-
- obj->~Object();
-
- This turns back the 'buf' into raw-memory.
-
- Enno
-